<script type="text/javascript">     

$(document).ready(function(){
                               
    // create new specification
    $("#create_new").click(function(){
        var name = $.trim($('#new_name').val());
        $.post("<?=site_url("/admin/finishes/create")?>", 
            { name: name },
            function(data){
                if(data.success==true){
                    var html_str = data.response;
                    Append_New_Spec(data.item.id, data.item.name);
                } else {
                    var html_str = data.response;
                }
                $("#new_response").html(html_str).hide().fadeIn();

            }, "json"
        );
        return false;
    }); 
    //disable form submition when pressing enter on text field
    $("#new_name").bind("keypress", function(e,a) {
        if (e.keyCode == 13) {
            $("#create_new").click();
            return false;
        }
    });

    function Append_New_Spec(id,name){

        var html = '';
        html += '<div class="list_block active">';
        html += ' <a class="title" href="<?=site_url('admin/finishes/edit')?>/'+id+'"> '+name+'</a>';
        html += ' <div class="buttons_block">';
        html += '   <a href="<?=site_url('admin/finishes/edit')?>/'+id+'" class="button">edit</a>';    
        html += '   <a href="<?=site_url('admin/finishes/deactivate')?>/'+id+'" class="button">deactivate</a>';
        html += '   <a href="<?=site_url('admin/finishes/remove')?>/'+id+'" class="button">delete</a>';
        html += ' </div">';
        html += '</div>';   

        $("#list_container").append(html);  
    }  

});
</script>

<div id="content">       

    <? if(is_array($response)){?>
    <div class="response">
        <span class="<?=$response["class"]?>"><?=$response["msg"]?></span>
    </div>
    <?}?>

    <h1>Product finishes</h1>

    <div class="live_search_msg"></div>

    <div id="list_container" class="content_block" style="width:100%; overflow:auto;"> 
    <? foreach($list as $item){?>

        <div class="list_block search <?=($item["Active_Finishes"]=='1') ? 'active' : 'inactive'?>">

            <span class="title"><?=$item['Name_Finishes']?></span>                
                                    
            <div class="buttons_block">
                <a href="<?=site_url('admin/finishes/edit/'.$item['id_Finishes'])?>" class="button">edit</a>       
                <? if ($item['Active_Finishes'] == 1){ ?>
                <a href="<?=site_url('admin/finishes/deactivate/'.$item['id_Finishes'])?>" class="button">deactivate</a>
                <? } else { ?> 
                <a href="<?=site_url('admin/finishes/activate/'.$item['id_Finishes'])?>" class="button">activate</a>
                <? } ?> 
                <a href="<?=site_url('admin/finishes/remove/'.$item['id_Finishes'])?>" class="button">delete</a>   
            </div>

        </div>   

    <? } ?>
    </div>

    <div class="content_block">
        <input type="text" id="new_name" maxlength="80" style="display:inline; width:200px" />
        <a id="create_new" href="#" class="button">ADD NEW</a>
        <div id="new_response"></div>
    </div>

</div>